package com.config;

import org.springframework.util.StringUtils;
import org.springframework.web.servlet.LocaleResolver;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;
/*
* 自定义国际化解析器*/
public class MyLocaleResolver implements LocaleResolver {
    /*解析请求*/
    @Override
    public Locale resolveLocale(HttpServletRequest request) {
        /*System.out.println("NI>>>>>>>>>>不出来？？");*/
        //获取请求参数中的语言请求
        String language = request.getParameter("l");
        Locale locale = Locale.getDefault();

        //判断请求中是否有国际化的请求参数
        if (!StringUtils.isEmpty(language)){
            //如果有的话，就用请求的语言
            String [] strings=language.split("_");
            locale=new Locale(strings[0],strings[1]);
        }
        return locale;
    }

    @Override
    public void setLocale(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Locale locale) {

    }
}
